package com.android.dexunshell;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class RefInvoke {
	public static Object invokeStaticMethod(String class_name, String method_name, Class[] pareType, Object[] pareValues) {
		try {
			Class obj_class = Class.forName(class_name);
			Method method = obj_class.getMethod(method_name, pareType);
			return method.invoke(null, pareValues);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public static Object invokeMethod(String class_name, String method_name, Object obj, Class[] pareType, Object[] pareValues) {
		try {
			Class obj_class = Class.forName(class_name);
			Method method = obj_class.getMethod(method_name, pareType);
			return method.invoke(obj, pareValues);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public static Object getFieldObject(String class_name, Object obj, String fieldName) {
		try {
			Class obj_class = Class.forName(class_name);
			Field field = obj_class.getDeclaredField(fieldName);
			field.setAccessible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public static Object getStaticFieldObject(String class_name, String fieldName) {
		try {
			Class obj_class = Class.forName(class_name);
			Field field = obj_class.getDeclaredField(fieldName);
			field.setAccessible(true);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return null;
	}
	
	public static void setFieldObject(String className, String fieldName, Object obj, Object fieldValue) {
		try {
			Class obj_class = Class.forName(className);
			Field field = obj_class.getDeclaredField(fieldName);
			field.setAccessible(true);
			field.set(obj, fieldValue);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void setStaticObject(String className, String fieldName, Object fieldValue) {
		try {
			Class obj_class = Class.forName(className);
			Field field = obj_class.getDeclaredField(fieldName);
			field.setAccessible(true);
			field.set(null, fieldValue);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
